addItem Method (Tree) |
This method adds an item under the root node or the selected node of the tree.
Syntax
oNewItem = treeID.root.addItem(oItemDefinition)
When called from a node other than root, the syntax is as follows:
oNewItem = treeNode.addItem(oItemDefinition)
To add an item in the tree as a "root" node, the syntax is as follows:
oNewItem = treeNode.addItem(oItemDefinition [, description])
Parameters
Parameter |
Description |
---|---|
oItemDefinition |
Required. Object that points to an XMLDOM object that contains the item to be added in the tree node. |
description |
Optional. String that denotes the description of the item to be added. |
Return Value
Returns the tree item of the new item that is added in the tree.
Remarks
The operation should be performed only on a parent tree node item (item with a "+" symbol before it indicating that it can be expanded).
When this function is called, the node is expanded, and any function associated with the onexpand property of the tree item is fired. Once expanded, it will have a "-" symbol in place of "+" indicating that the item is already expanded.
If the return value of the function is set to 'false', then the item will not be expanded.
The description parameter is optional and denotes the description of the item to be added. To add an item with a description in the tree root, the following conditions need to be followed:
- A schema is not defined for the item to be added. Even if defined, the <description> is not defined for the Schema.
- The item is to be added as the root of the tree (<treeID>.addItem is called).
However, for these items, events like onselect, onexpand etc., will not function.
Example
The following example shows how the above method can be used to add an item to the menutree, defined in the example given for the Tree library.
<!-- Template of the item to be added to the tree --> <script type="cordys/xml" id="newCountryXML"> <Country> <caption>India</caption> <description>India</description> </Country> </xml> //Function that adds item to the existing menutree function addNewItem() { //Adding an item that depends on the new schema var newCountryItem = cordys.cloneXMLDocument(newCountryXML.XMLDocument); menutree.addItem(newCountryItem); }